home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 32 / Mac Magazin and MacEasy Magazine CD - Issue 32.iso / Multimedia / PlayerPRO 4.5.5 Dev.Kit / Plug-Ins / Sound Filters Plugs / Smooth.c < prev    next >
C/C++ Source or Header  |  1995-10-08  |  2KB  |  85 lines

  1. /*    Smooth            */
  2. /*    v 0.2            */
  3. /*    1995 by Liane    */
  4.  
  5. //    Usage:
  6. //    Works like a low pass filter, removing high
  7. //    harmonics generated by a low sampling rate.
  8. //    Works on the selected part or all the waveform
  9. //    if there is no selection.
  10. //    Not very accurate, but pretty fast to write !!!
  11.  
  12. #include "MAD.h"
  13. #include "PPPlug.h"
  14.  
  15. #if defined(powerc) || defined(__powerc)
  16. enum {
  17.         PlayerPROPlug = kCStackBased
  18.         | RESULT_SIZE(SIZE_CODE( sizeof(OSErr)))
  19.         | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof( sData*)))
  20.         | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof( long)))
  21.         | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof( long)))
  22.         | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof( PPInfoPlug*)))
  23. };
  24.  
  25. ProcInfoType __procinfo = PlayerPROPlug;
  26. #else
  27. #include <A4Stuff.h>
  28. #endif
  29.  
  30. OSErr main(     sData                    *theData,
  31.                 long                    SelectionStart,
  32.                 long                    SelectionEnd,
  33.                 PPInfoPlug                *thePPInfoPlug)
  34. {
  35. long    i, length, temp, prevtemp, nexttemp, work;
  36.  
  37.     if (SelectionStart == SelectionEnd) {
  38.         SelectionStart = 0;
  39.         SelectionEnd = theData->size;
  40.     }
  41.     length = SelectionEnd - SelectionStart - 1;
  42.  
  43.     switch( theData->amp)
  44.     {
  45.         case 8:
  46.         {
  47.             Ptr    SamplePtr = (theData->data) + SelectionStart;
  48.             
  49.             prevtemp = *SamplePtr++;
  50.             temp = *SamplePtr++;
  51.             for( i = 1; i < length; i++)
  52.             {
  53.                 nexttemp = *SamplePtr--;
  54.                 
  55.                 work = ((prevtemp + nexttemp) + (temp * 6)) >> 3;
  56.         
  57.                 *SamplePtr++ = work;
  58.                 prevtemp = temp;
  59.                 temp = nexttemp;
  60.                 SamplePtr++;
  61.             }
  62.         } break;
  63.  
  64.         case 16:
  65.         {
  66.             short    *SamplePtr = (short*) theData->data + (SelectionStart / 2);
  67.             
  68.             prevtemp = *SamplePtr++;
  69.             temp = *SamplePtr++;
  70.             for( i = 1; i < length / 2; i++)
  71.             {
  72.                 nexttemp = *SamplePtr--;
  73.                 
  74.                 work = ((prevtemp + nexttemp) + (temp * 6)) >> 3;
  75.         
  76.                 *SamplePtr++ = work;
  77.                 prevtemp = temp;
  78.                 temp = nexttemp;
  79.                 SamplePtr++;
  80.             }
  81.         } break;
  82.     }
  83.  
  84.     return noErr;
  85. }